<?php
class Assignment extends AppModel {
	var $name = 'Assignment';
	var $primaryKey = 'assignment_id';

	var $validate = array(
					'resident_id' => VALID_NUMBER,
					'semester_id' => VALID_NUMBER,
					'semester_apartement_id' => VALID_NUMBER,
	);

	var $belongsTo = array('Semester' =>
					array('className' => 'Semester',
									'foreignKey' => 'semester_id'),
					'Resident' =>
					array('className' => 'Resident',
								'foreignKey' => 'resident_id'),
					'SemesterApartement' =>
					array('className' => 'SemesterApartement',
								'foreignKey' => 'semester_apartement_id')
					);

	function findResidents($semesterId, $apartementId) {
		$residents = $this->query("SELECT Resident.resident_id, Resident.firstName, Resident.lastName from 
									residents as Resident, 
									assignments as a,
									semester_apartements as sa
									where sa.semester_apartement_id = a.semester_apartement_id AND
									a.resident_id = Resident.resident_id AND
									sa.apartement_id = '$apartementId' AND
									sa.semester_id = '$semesterId'
									ORDER BY Resident.lastName, Resident.firstName");
		return $residents;
	}
}
?>
